package jvProjects.imageDeformation;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import deformation.DeformationGenerator;
import deformation.DeformationGenerator.DeformationType;
import jv.number.PuDouble;
import jv.object.PsDebug;
import jv.object.PsUpdateIf;
import jv.project.PjProject_IP;
import jvDeformation.gui.ComboBox;
import jvDeformation.gui.JvDeformationDisplayPanel;
import jvDeformation.gui.RadioBox;

/**
 * Info panel of tutorial project. Each project, as well as each geometry, may have
 * an info panel for inspecting and steering the instance. Modifications in the panel
 * should result in a call to <code>project.update(Object)</code>.
 * <p>
 * Panel adds simple sliders for modifying integer values of the project. The sliders
 * are children of the project and send <code>update(Object)</code> whenever they change
 * by user interaction.
 * <p>
 * This info panel is optional and can be removed without any changes in the project.
 * Each info panel must follow special naming conventions such that JavaView is able to
 * show it automatically, or on request. The class name must be identical to the class
 * name of the corresponding class with the suffix '_IP' attached. IP means InfoPanel.
 * 
 * @see			jv.project.PjProject
 * @author		Konrad Polthier
 * @version		28.11.00, 1.50 revised (kp) Applet simplified for beginners.<br>
 *					20.03.00, 1.10 revised (kp) Sliders moved to project.<br>
 *					05.08.99, 1.00 created (kp)
 */
public class PjImageDeformation_IP extends PjProject_IP implements ActionListener {
	protected	PjImageDeformation		imageDeformationProject;
	protected	Panel				sliderPanel;
	protected	Label				lArea;
	
	
	
	// Declare your GUI objects here, e.g. a button
	protected 	Button				bLoad;
	protected 	Button				bsave;
	protected	Checkbox			drawHandler;
	protected	Checkbox			hq;
	boolean sticked =false;
	private JvDeformationDisplayPanel ddp = new JvDeformationDisplayPanel();
	public PjImageDeformation_IP() {
		super();
		// Add title label which will later display the title of the project.
		addTitle("");
		drawHandler = new Checkbox("Draw Handler");
		hq = new Checkbox("HQ", false);
		//drawHandler.addItemListener(this);
		// The GUI object declared above needs to be created here
		bLoad = new Button("Load new Image");
		bLoad.addActionListener(this);
		bsave = new Button("Save");
		bsave.addActionListener(this);
		add(ddp );
		add(bLoad);
		//add(cDeformationType.getComponent());
		//add(bStick);
		//add(bTest);
		//add(bopenTwo);
		//add(bfuse);
		//add(dFusionGlider.getInfoPanel());
		Panel p = new Panel(new GridLayout(1, 0));
		p.add(drawHandler);
		p.add(hq);
		p.add(bsave);
		this.add(p);
		
		if (getClass() == PjImageDeformation_IP.class)
			init();
	}
	
	public void setParent(PsUpdateIf parent) {
		super.setParent(parent);
		imageDeformationProject = (PjImageDeformation)parent;
		setTitle(imageDeformationProject.getName());
		ddp.setJvDeformationDisplay(imageDeformationProject.defdis);
	}
	
	/**
	* Here we arrive from outside world of this panel, e.g. if
	* project has changed somewhere else and must update its panel. Such an update
	* is automatically by superclasses of PjProject.
	*/
	public boolean update(Object event) {
		if (imageDeformationProject==null) {
			if (PsDebug.WARNING) PsDebug.warning("missing parent, setParent not called");
			return false;
		}
		return super.update(event);
	}
	/**
	 * Handle action events invoked from buttons, menu items, text fields.
	 */
	public void actionPerformed(ActionEvent event) {
		if (imageDeformationProject==null)
			return;
		Object source = event.getSource();
		if(source == bLoad){
			imageDeformationProject.loadImage();
		} else if(source == bsave){
			bsave.setEnabled(false);
		imageDeformationProject.saveImage(drawHandler.getState(), hq.getState());
		bsave.setEnabled(true);
	}	
	}
}

